package com.wonderland.lucy.showcase.security.web;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.wonderland.lucy.showcase.security.model.User;
import com.wonderland.lucy.showcase.security.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/security/user")
public class UserController {

    @Autowired
    private UserService userService;


    @RequestMapping(method = RequestMethod.GET)
    public String user(Model model, User user) throws JsonProcessingException {
        model.addAttribute("userList", userService.getUserList(user));
        return "security/user";
    }

    @RequestMapping(value = "/getUserList", method = RequestMethod.GET)
    @ResponseBody
    public List<User> getUserListPage(User user) {
        return userService.getUserList(user);
    }

}
